
/****** Object:  StoredProcedure [dbo].[web_ins_card]    Script Date: 10/19/2013 09:22:25 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

--IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'web_ins_card')
DROP procedure web_ins_card
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE procedure [dbo].[web_ins_card] 
	@pastabos varchar(255),
	@imkodas varchar(100),
	@kortele varchar(100)

AS
BEGIN
declare @nr varchar(255)

  
select @nr = max(N51_KODAS_KT) from N51_SUTH where N51_KODAS_KT like 'WEB%'
if (@nr is null)
  set @nr = 'WEB1'
else			
  set @nr = 'WEB'+convert(varchar(12),cast(SUBSTRING(@nr,4,100) as integer)+1)
  
while (1=1)
begin
If exists(select * from N51_SUTH where N51_KODAS_KT=@nr)
  set @nr = 'WEB'+convert(varchar(12),cast(SUBSTRING(@nr,4,100) as integer)+1)
else
  break
end
  
  insert into N51_SUTH (N51_KODAS_KT,N51_KODAS_KS,N51_PASTABOS,N51_PAV,N51_TIPAS) values (@nr,@imkodas,@pastabos,@kortele,2 )

  insert into #ttrez values(@nr)
END

GO

